package org.aynu.paymentservice.controller;

import org.aynu.paymentservice.common.PaymentsResponse;
import org.aynu.paymentservice.domain.Payments;
import org.aynu.paymentservice.service.IPaymentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 支付控制器
 *
 * @author 小粥
 * @since 2025/03/04
 */
@RestController
@RequestMapping("/payments")
public class PaymentsController {

    private final IPaymentsService paymentsService;

    @Autowired
    public PaymentsController(IPaymentsService paymentsService) {
        this.paymentsService = paymentsService;
    }

    /**
     * 创建支付记录
     *
     * @param request 支付请求
     * @return {@link PaymentsResponse }<{@link Integer }>
     * @author 小粥
     * @since 2025/03/04
     */
    @RequestMapping("/createPayment")
    public PaymentsResponse<Integer> createPayment(@RequestBody Payments request) {
        if (request.getOrderId() == null && request.getFeeId() == null) {
            return PaymentsResponse.error(400, "必须提供 orderId 或 feeId");
        }
        request.setStatus("支付成功");
        return paymentsService.createPayment(request);
    }
}